<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
    -->
    <b-modal ref="my-modal" size="xl" title="找回用户" scrollable no-close-on-backdrop centered>
        <div class="d-block text-center">
            <div class="card card-custom gutter-b example example-compact" id="tableUserDeleteBody">
                <div class="card-header">
                <div class="card-title">
                    <span class="card-icon">              
                    <i class="text-dark-50 flaticon-search-magnifier-interface-symbol"></i>
                    </span>
                    <h3 class="card-label"> 查询区域 </h3>
                </div>
                <div class="card-toolbar">
                    <div class="example-tools justify-content-center">
                    <!-- <span data-toggle="tooltip" class="example-toggle"></span>
                    <span data-toggle="tooltip" class="example-copy"></span> -->
                    </div>
                </div>
                </div>
                <div class="card-body">
                    <!--查询条件-->
                    <div class="m-form m-form--fit m-form--label-align-left m-form--group-seperator-dashed">
                      <div class="m-portlet__body">	
                        <div class="form-group m-form__group row">
                          <!-- <div class="col-lg-2">
                            <v-text-field v-model="searchForm.xt_departinfo_name" label="隶属部门">
                            </v-text-field>
                          </div>
                          <div class="col-lg-2">
                            <v-text-field v-model="searchForm.xt_post_name" label="岗位">
                            </v-text-field>
                          </div>
                          <div class="col-lg-2">
                            <v-text-field v-model="searchForm.xt_userinfo_name" label="账号">
                            </v-text-field>
                          </div>    
                          <div class="col-lg-1">
                            <v-text-field v-model="searchForm.xt_userinfo_realName" label="姓名">
                            </v-text-field>
                          </div>   -->
                          <label class="col-form-label">隶属部门:</label>
                          <div class="col-md-2">
                              <input type="text" class="form-control" v-model="searchForm.departInfoName" placeholder="请输入">
                          </div>
                          <label class="col-form-label">岗位:</label>
                          <div class="col-md-2">
                              <input type="text" class="form-control" v-model="searchForm.postName" placeholder="请输入">
                          </div>
                          <label class="col-form-label">姓名:</label>
                          <div class="col-md-2">
                              <input type="text" class="form-control" v-model="searchForm.name" placeholder="请输入">
                          </div>
                          <label class="col-form-label">账号:</label>
                          <div class="col-md-2">
                              <input type="text" class="form-control" v-model="searchForm.account" placeholder="请输入">
                          </div>                                      
                        </div>
                        <div class="form-group m-form__group row">                  
                          <label class="col-form-label">身份证号:</label>
                          <div class="col-md-2">
                              <input type="text" class="form-control" v-model="searchForm.idCard" placeholder="请输入">
                          </div>
                          <label class="col-form-label">邮箱:</label>
                          <div class="col-md-2">
                              <input type="text" class="form-control" v-model="searchForm.email" placeholder="请输入">
                          </div>
                          <label class="col-form-label">联系电话:</label>
                          <div class="col-md-2">
                              <input type="text" class="form-control" v-model="searchForm.phone" placeholder="请输入">
                          </div>  
                          <b-button :pressed="false" variant="btn btn-primary font-weight-bold mr-2" @click="search()"><span><i class="fa fa-search"></i><span>查询</span></span></b-button>
                          <b-button :pressed="false" variant="btn btn-light font-weight-bold mr-2"  @click="resetAll()"> <span><span>清空条件</span></span></b-button>
                        </div>
                      </div>           
                    </div>
                </div>
                <!--分页组件-->
                <el-table style="width: 100%" stripe border @selection-change="handleSelectionChange" highlight-current-row :data="userDataList" >
                <!-- 复选框 -->
                <el-table-column type="selection" width="40"></el-table-column>
                <el-table-column label="序号" min-width="50">
                    <template slot-scope="scope">
                    {{scope.$index+1}} 
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="account"   label="账号" min-width="100"></el-table-column>
                <el-table-column align="center" prop="name" label="姓名" min-width="100"></el-table-column>
                <el-table-column align="center" prop="idCard"   label="身份证号" min-width="200"></el-table-column>
                <el-table-column align="center" prop="phone"  label="联系电话" min-width="110"></el-table-column>
                <el-table-column align="center" prop="email"  label="邮箱" min-width="200"></el-table-column>
                <el-table-column align="center" label="性别" min-width="100">
                    <template slot-scope="scope">
                    <span>{{scope.row.set }}</span>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="inTime"  label="入职日期" min-width="100"></el-table-column>          
                </el-table>
                <div class="block">
                <el-pagination
                    hide-on-single-page   
                    @size-change="handleSizeChange"        
                    @current-change="handleCurrentChange"  
                    :current-page="pageNo"                
                    :page-sizes="[5, 10, 30, 50]"          
                    :page-size="pageSize"			  
                    layout="->,total, sizes, prev, pager, next, jumper"
                    :total="totalCount">		
                </el-pagination>
                </div>
            </div>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->
            <button type="button" class="btn btn-light-danger font-weight-bold mr-2" block @click="hideModal">
                <i class="icon-xl fa fa-times"></i>取消
            </button> 
            <button type="button" class="btn btn-light-success font-weight-bold mr-2" @click="recoverXtUserinfo">
                <i class="icon-xl fas fa-save"></i> 恢复用户
            </button>
        </template>
     </b-modal>
</template>  
<script>
  import Swal from "sweetalert2";
  import apiUtil from "@/core/util/apiUtil.js"; 
  import { handleNotify,handleAlert,handleConfirm,showWating,closeWating} from "@/core/util/jehcUtil.js";
  export default {
    data(){
      return{
        searchForm:{account: "",name:"",departInfoName:"",postName:"",idCard:"",phone:"",email:""},
        userDataList:[],
        sels: [], //当前选框选中的值
        pageNo:1,      // 默认当前是第一页
        pageSize:5,    // 当前每页的数据是5条
        totalCount:0   // 总数默认为0
      }
    },
    components: {
    },
    mounted() {
        this.initList();   // 按当前的页号和每页的数据量进行查询
    },
    methods:{
      showModal() {        
        this.$refs['my-modal'].show();
        this.initList();   // 按当前的页号和每页的数据量进行查询
      },
      hideModal() {
        this.$refs['my-modal'].hide()
      },
      toggleModal() {
        // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
        this.$refs['my-modal'].toggle('#toggle-btn')
      },
      initList(){
        showWating({renderBody:"tableUserDeleteBody"});
        var params = {};
        params.usePageNo = true;//采用第几页进行分页（兼容）
        params.pageSize = this.pageSize;//页面显示记录条数，在页面显示每页显示多少项的时候
        params.pageNo = this.pageNo;//开始的记录序号   
        params.searchJson = JSON.stringify(this.searchForm);//为form元素     
        apiUtil.queryPage(process.env.VUE_APP_SYS_API+"/xtUserinfo/deleted/list", params).then(({ data }) => {
          this.userDataList = data.data;//给结果集赋值
          this.totalCount = data.total;// 获取当前数据的总数    
          this.getGender();         
        });
      },      
      handleSelectionChange(sels) {//获取选中的值
        this.sels = sels;
        console.log("选中的值",sels.map((item) => item.id));
      },
      recoverXtUserinfo(){ // 恢复用户
        if(this.sels.length === 0){
          handleAlert("请选择恢复的用户", "warning", 3)
          return;
        }
        // 恢复前提示
        this.$confirm("确认恢复选择的用户吗?", "提示", {type: "warning",}).then(() => {
          let id = this.sels.map((item) => item.id);
          // 根据后台想要的参数格式选择
          // console.log(ids.join(",")); //1,2,3,4
          // console.log(ids); //[1,2,3,4]
          let ids = id.join(",");
          console.log(ids);
          let params = {id:ids};
          apiUtil.query(process.env.VUE_APP_SYS_API+"/xtUserinfo/recover",params).then(data=>{
            if(data.data.success){
              handleAlert("恢复员工成功", "success", 3);
              this.$emit("change",data);//组件传值，即向父级模态框中传递值，采用change方式，目标刷新主列表使用
              this.search();
            }else {
              handleAlert("恢复员工失败", "error", 3);
            }
          });
        }).catch(()=>{});//注意这里，这里是重点！！！;        
      },
      handleSizeChange(val) { // 修改每页所存数据量的值所触发的函数
        this.pageSize = val;  // 修改页的大小
        this.initList();       // 按新的pageNo和pageSize进行查询
      },
      handleCurrentChange(val) { // 修改当前页所触发的函数
        this.pageNo = val;       // 更新当前的页
        this.initList();          // 按新的pageNo和pageSize进行查询
      },
      search(){
        this.pageNo = 1;       // 更新当前的页
        this.initList();          // 按新的pageNo和pageSize进行查询
      },
      resetAll(){
        Object.assign(this.$data.searchForm, this.$options.data().searchForm);
        this.search();
      },      
      getGender:function(){
        this.userDataList.forEach(item => {
          if(null != item.sex && '' != item.sex){
            apiUtil.get(process.env.VUE_APP_SYS_API+"/xtDataDictionary/get",item.sex).then(data=>{            
                item.sex = data.data.name;
            });
          }
36     })
      }
      // formatGender: function( row, column,cellValue,columnIndex) {
      //   let xt_userinfo_sex = row.xt_userinfo_sex;
      //   let genderName="∨";
      //   if(xt_userinfo_sex == null || xt_userinfo_sex == ""){
      //     return genderName;
      //   }
      //   apiUtil.get(process.env.VUE_APP_SYS_API+"/xtDataDictionary/get",xt_userinfo_sex).then(data=>{
      //       console.log("-------",columnIndex);
      //       row["xt_userinfo_sex"] === "未下发";
      //       // row.xt_userinfo_sex = data.data.xt_data_dictionary_name
      //       // return data.data.xt_data_dictionary_name;

            
      //   });
      //   return genderName;
      //   // return row.xt_userinfo_sex == '1' ? "男" : "女" 
      // },
    }
  };
</script>